<?php
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2007 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                     |
|                                                                             |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE   PROGRAM   AND  ASSOCIATED  DOCUMENTATION   THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").   |
| PLEASE   REVIEW   THE  TERMS  AND   CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY   BEFORE   INSTALLING   OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING   OR   OTHERWISE   USING   THE   SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE   AGREEMENT.   IF  YOU    ARE  NOT  WILLING   TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS   COPYRIGHTS   AND |
| OTHER   INTELLECTUAL   PROPERTY   RIGHTS    PROTECT   THE   SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS   TO  USE |
| THE  SOFTWARE   AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                             |
| The Initial Developer of the Original Code is Ruslan R. Fazliev             |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2007           |
| Ruslan R. Fazliev. All Rights Reserved.                                     |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: cc_mm.php,v 1.17.2.2 2007/03/22 13:55:10 svowl Exp $
#

if (!defined('XCART_START')) { header("Location: ../"); die("Access denied"); }

x_load('http');

$post = array();
$post[] = "TRANSACTIONTYPE=sale";
$post[] = "MERCHANTACCOUNTID=".$module_params['param01'];
$post[] = "CLIENTID=".$module_params['param03'];
$post[] = "BNAME=".$userinfo["card_name"];
$post[] = "CARDHOLDERNUMBER=".$userinfo["card_number"];
$post[] = "CVV2=".$userinfo["card_cvv2"];
$post[] = "EXPIRESMONTH=".substr($userinfo['card_expire'],0,2);
$post[] = "EXPIRESYEAR=20".substr($userinfo['card_expire'],2,2);;
$post[] = "BADDRESS1=".$userinfo["b_address"];
$post[] = "BSTATE=".$userinfo["b_state"];
$post[] = "BCITY=".$userinfo["b_city"];
$post[] = "BCOUNTRY=".$userinfo["b_country"];
$post[] = "BZIPCODE=".$userinfo["b_zipcode"];
$post[] = "AMOUNT=".$cart["total_cost"];
$post[] = "ORDERNO=".$module_params["param02"].join("-",$secure_oid);

list($a,$return) = func_https_request("POST","https://gateway.mbs-us.com:443/ccgateway.asp",$post,"&","","application/x-www-form-urlencoded",$http_location."/payment/cc_mm.php");

# approved=N&msg=Your Credit Card was Declined: TEST MODE
# approved=N&msg=Your Credit Card was Declined: Request Declined: DECLINED

$tmp_return = $return;
$return = trim($return);
$ret_arr = explode("&", $return);
$return = array();
foreach ($ret_arr as $ret) {
	$ret = explode("=", $ret);
	$return[$ret[0]] = $ret[1];
}
if (!isset($return['APPROVED'])) {
	$bill_output["code"] = 2;
	$bill_output["billmes"] = $tmp_return;
} elseif ($return['APPROVED'] == "N") {
	$bill_output["code"] = 2;
	$bill_output["billmes"] = $return['MSG'];
} elseif ($return['APPROVED'] == "Y") {
	$bill_output["code"] = 1;
	$bill_output["billmes"] = $return['MSG'];
}
?>
